package by.bsuir.entity;
import java.io.Serializable;
import java.util.*;

import by.bsuir.util.Component;

/**
 * @author Raman_Pliashkou
 */
public class Node implements Component, Serializable {

    private static final long serialVersionUID = -2005676516016750442L;

    private String host;

    private String ip;

    private String name;

    private String link;

    boolean type;

    boolean typeShare;

    public Node() {
        nodes = new ArrayList<Component>();
    }

    public Node(String name) {
        this();
        this.name = name;
    }

    public Node(String host, String ip, String name, String link, boolean type) {
        this();
        this.host = host;
        this.ip = ip;
        this.name = name;
        this.link = link;
        this.type = type;
    }

    private List<Component> nodes = null;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public String getIp() {
        return ip;
    }

    public void setIp(String ip) {
        this.ip = ip;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getLink() {
        return link;
    }

    public void setLink(String link) {
        this.link = link;
    }

    public boolean isType() {
        return type;
    }

    public void setType(boolean type) {
        this.type = type;
    }

    public List<Component> getNodes() {
        return nodes;
    }

    public void setNodes(List<Component> nodes) {
        this.nodes = nodes;
    }

    public boolean isFile() {
        return !type ? true : false;
    }

    public boolean isFolder() {
        return type ? true : false;
    }

    public void add(Component node) {
        nodes.add(node);
    }

    public void remove(Component node) {
        nodes.remove(node);
    }

    public List<Component> getChild() {
        return nodes;
    }
    public boolean isTypeShare() {
        return typeShare;
    }

    public void setTypeShare(boolean typeShare) {
        this.typeShare = typeShare;
    }

    public Iterator createIterator() {
        return nodes.iterator();
    }

    public String getShortName() {
        return name.substring(0,name.indexOf("/"));
    }

}
